﻿#include "cadresearch.h"
#include "ui_cadresearch.h"
#include <QDebug>
#include <QSqlQuery>
#include <QMessageBox>

int flog=0;

CadreSearch::CadreSearch(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::CadreSearch)
{
    ui->setupUi(this);
    this->setWindowTitle("干部信息查询");
    this->setGeometry(400,200,1100,750);
    ui->treeWidget->setHeaderHidden(true);
    ui->treeWidget_2->setHeaderHidden(true);
    //ui->treeWidget_2->setItemsExpandable(false);
    ui->treeWidget_2->expandAll();
    connect(&chooseCadre,SIGNAL(sendNum(QString)),this,SLOT(recvSend(QString)));
    this->setWindowFlags(Qt::WindowStaysOnTopHint);

    initTreeWidget();


}

CadreSearch::~CadreSearch()
{
    delete ui;
}

//初始化treeWidget
void CadreSearch::initTreeWidget()
{
    QSqlQuery query;
    //民族
    query.exec("select Nation from NationCode");
    while(query.next())
    {
        QTreeWidgetItem *child=new QTreeWidgetItem(ui->treeWidget->itemAt(0,30));
        child->setText(0,query.value(0).toString());
    }
    //在职or全日学历
    query.exec("select Education from EducationCode");
    while(query.next())
    {
        QTreeWidgetItem *childw=new QTreeWidgetItem(ui->treeWidget->itemAt(0,300));
        childw->setText(0,query.value(0).toString());

        QTreeWidgetItem *childs=new QTreeWidgetItem(ui->treeWidget->itemAt(0,360));
        childs->setText(0,query.value(0).toString());
    }
    //在职or全日学位
    query.exec("select Degree from DegreeCode");
    while(query.next())
    {
        QTreeWidgetItem *childw=new QTreeWidgetItem(ui->treeWidget->itemAt(0,330));
        childw->setText(0,query.value(0).toString());

        QTreeWidgetItem *childs=new QTreeWidgetItem(ui->treeWidget->itemAt(0,390));
        childs->setText(0,query.value(0).toString());
    }
    //单位名称
    query.exec("select unitname from unit");
    while(query.next())
    {
        QTreeWidgetItem *childu=new QTreeWidgetItem(ui->treeWidget->itemAt(0,450));
        childu->setText(0,query.value(0).toString());
    }
    //单位层次
    query.exec("select UnitGradationName from UnitGradationCode");
    while(query.next())
    {
        QTreeWidgetItem *child=new QTreeWidgetItem(ui->treeWidget->itemAt(0,480));
        child->setText(0,query.value(0).toString());
    }
    //单位属性
    query.exec("select UnitNatrueName from UnitNatrueCode");
    while(query.next())
    {
        QTreeWidgetItem *childu=new QTreeWidgetItem(ui->treeWidget->itemAt(0,510));
        childu->setText(0,query.value(0).toString());
    }
    //单位性质
    query.exec("select UnitCategory from UnitCategoryCode");
    while(query.next())
    {
        QTreeWidgetItem *childu=new QTreeWidgetItem(ui->treeWidget->itemAt(0,520));
        childu->setText(0,query.value(0).toString());
    }
    //单位类别
    query.exec("select UnitOfCategoryName from UnitOfCategoryCode");
    while(query.next())
    {
        QTreeWidgetItem *child=new QTreeWidgetItem(ui->treeWidget->itemAt(0,540));
        child->setText(0,query.value(0).toString());
    }
    //单位级别
    query.exec("select UnitLevel from UnitLevelCode");
    while(query.next())
    {
        QTreeWidgetItem *childu=new QTreeWidgetItem(ui->treeWidget->itemAt(0,570));
        childu->setText(0,query.value(0).toString());
    }
    //单位隶属关系
    query.exec("select AffiliationName from AffiliationCode");
    while(query.next())
    {
        QTreeWidgetItem *childu=new QTreeWidgetItem(ui->treeWidget->itemAt(0,600));
        childu->setText(0,query.value(0).toString());
    }

}

void CadreSearch::on_buttonSearch_clicked()
{
    //刘俊廷部分
    QVector<QString> ljt;
    QVector<QString> wtm;
    QString id="NULL";
    QString judgeall;
    QString name;
    bool namenotempty=!ui->name->text().isEmpty();
    QString unit;
    bool unitnotempty=!ui->unit->text().isEmpty();
    QString zhiwu;
    bool zhiwunotempty=!ui->zhiwu->text().isEmpty();
    QString schooledu;
    bool schooledunotempty=!ui->schooledu->text().isEmpty();
    QString workedu;
    bool workedunotempty=!ui->workedu->text().isEmpty();

    QString birth;
    QString births=ui->birthS->text();                       //出生日期start
    QString birthe=ui->birthE->text();                       //出生日期end

    QString joinworktime;
    QString joinworks=ui->joinworks->text();
    QString joinworke=ui->joinworke->text();

    QString rudangtime;
    QString rudangs=ui->rudangs->text();
    QString rudange=ui->rudange->text();

    QString renzhitime;
    QString renzhis=ui->renzhis->text();
    QString renzhie=ui->renzhie->text();

    QSqlQuery selectall;
    QSqlQuery changejiguan;
    judgeall=QString("select distinct c.IDNum from CadreInfo c,unit u,Post p,Edu e where c.IDNum=p.IDNum and c.IDNum=e.IDNum and c.UnitID=u.unitid ");

    QString jiguan;
    QString jiguanname;
    QString jiguanshengid;
    bool jiguannotempty=!ui->jiguanplace->text().isEmpty();
    if(jiguannotempty){
        if(ui->comboBox->currentText()=="属于"){
            jiguanname=ui->jiguanplace->text();
            changejiguan.exec(QString("select SUBSTRING(AdminAreaID,1,2) from AdminAreaCode where AdminArea like '%%1%'").arg(jiguanname));
            while(changejiguan.next()){
                jiguanshengid=changejiguan.value(0).toString();
                jiguan=QString(" AND SUBSTRING(c.NativePlace,1,2)='%1' ").arg(jiguanshengid);
            }
        }
         if(ui->comboBox->currentText()=="不属于"){
             jiguanname=ui->jiguanplace->text();

             changejiguan.exec(QString("select SUBSTRING(AdminAreaID,1,2) from AdminAreaCode where AdminArea like '%%1%'").arg(jiguanname));
             while(changejiguan.next()){
                 jiguanshengid=changejiguan.value(0).toString();

                 jiguan=QString(" AND SUBSTRING(c.NativePlace,1,2)!='%1' ").arg(jiguanshengid);
             }
         }
    }

    QString birthplace;
    QString birthplacename;
    bool birthplacenotempty=!ui->birthplace->text().isEmpty();
    if(birthplacenotempty){
        birthplacename=ui->birthplace->text();
        if(ui->comboBox_2->currentText()=="属于"){
            birthplace=QString(" AND BirthPlace like '%%1%' ").arg(birthplacename);
        }
        if(ui->comboBox_2->currentText()=="不属于"){
            birthplace=QString(" AND BirthPlace not like '%%1%' ").arg(birthplacename);
        }
    }

    QString status;//干部状态
    QString threeone; //三龄一历
    if(ui->ischeckBox->isChecked()&&!ui->notcheckBox->isChecked()){
        threeone=" AND c.ThreeOne='0'";
    }
    if(ui->notcheckBox->isChecked()&&!ui->ischeckBox->isChecked()){
        threeone=" AND c.ThreeOne='1'";
    }

    if(ui->zaizhicheckBox->isChecked()&&!ui->lituicheckBox->isChecked()&&!ui->others->isChecked()){
        status=QString(" AND c.ManageStatusID='%1' ").arg("1");//在职
    }
    if(ui->lituicheckBox->isChecked()&&!ui->others->isChecked()&&!ui->zaizhicheckBox->isChecked()){
        status=QString(" AND c.ManageStatusID='%1' ").arg("2");//离退
    }
    if(ui->others->isChecked()&&!ui->zaizhicheckBox->isChecked()&&!ui->lituicheckBox->isChecked()){
        status=QString(" AND c.ManageStatusID='%1' ").arg("9");//其他
    }
    //选三个
    if(ui->zaizhicheckBox->isChecked()&&ui->lituicheckBox->isChecked()&&ui->others->isChecked()){
        status=" AND (c.ManageStatusID='1' or c.ManageStatusID='2' or c.ManageStatusID='9')";
    }
    //选两个
    if(ui->zaizhicheckBox->isChecked()&&ui->lituicheckBox->isChecked()&&!ui->others->isChecked()){
        status=" AND (c.ManageStatusID='1' or c.ManageStatusID='2')";
    }
    if(ui->zaizhicheckBox->isChecked()&&!ui->lituicheckBox->isChecked()&&ui->others->isChecked()){
        status=" AND (c.ManageStatusID='1' or c.ManageStatusID='9')";
    }
    if(!ui->zaizhicheckBox->isChecked()&&ui->lituicheckBox->isChecked()&&ui->others->isChecked()){
        status=" AND (c.ManageStatusID='9' or c.ManageStatusID='2')";
    }

    if(unitnotempty){
        unit=QString(" AND u.unitname='%1'").arg(ui->unit->text());
    }
    if(zhiwunotempty){
        zhiwu=QString(" and p.PostName='%1' ").arg(ui->zhiwu->text());
    }
    if(namenotempty){
        name=QString(" AND c.CadreName like '%%1%' ").arg(ui->name->text());
    }

    //专业表二选一
    if(schooledunotempty){
        schooledu=QString(" AND e.Major='%1' and e.WorkORSchool=1 ").arg(ui->schooledu->text());
    }
    if(workedunotempty){
        workedu=QString(" AND e.Major='%1' and e.WorkORSchool=0 ").arg(ui->workedu->text());
    }

    birth=QString(" and c.Birth>'%1' and c.Birth<'%2'").arg(births).arg(birthe);
    joinworktime=QString(" and c.JoinWorkTime>'%1' and c.JoinWorkTime<'%2'").arg(joinworks).arg(joinworke);

    rudangtime=QString(" and c.PartyTime>'%1' and c.PartyTime<'%2'").arg(rudangs).arg(rudange);
    renzhitime=QString(" and p.PostTime>'%1' and p.PostTime<'%2' and p.QualifyType=0").arg(renzhis).arg(renzhie);

    if(!ui->rudangcheck->isChecked()){
        rudangtime="";
    }
    if(!ui->joinworkcheck->isChecked()){
        joinworktime="";
    }
    if(!ui->renzhicheck->isChecked()){
        renzhitime="";
    }
    judgeall=judgeall+zhiwu+name+unit+workedu+schooledu+birth+joinworktime+rudangtime+renzhitime+status+threeone+jiguan+birthplace;
    qDebug()<<judgeall;
    selectall.exec(judgeall);
    while(selectall.next()){
        id=selectall.value(0).toString();
//        qDebug()<<id;
        ljt.append(id);
//        emit sendData3(id);//发送查询的干部IDNum

//        this->close();

    }
    //----------------------------------------------------
    //王天美部分
    //----------------------------------------------------
    chooseCadre.clearTableWidget();

    QString sqlUnit;
    QString sqlAll;
    QString sqlAddEdu;
    QSqlQuery queryAll;
    QSqlQuery queryNation;
    QSqlQuery queryPolitic;
    QSqlQuery queryManageStatus;
    QSqlQuery queryRank;
    QSqlQuery queryEdu;
    QSqlQuery queryDeg;
    QSqlQuery queryUnit;
    QSqlQuery query;

    QString birthS = ui->birthS->text();
    QString birthE = ui->birthE->text();
    QString birthScale = QString(" Birth >= '%1' and Birth <= '%2'").arg(birthS).arg(birthE);

    QString idNum="NULL";
    int unitId;
    QString sex;
    QString nation;
    QString politic;
    QString threeOne;
    QString idenCate;
    QString manageStatus;
    QString rank;
    QString eduw;
    QString edus;
    QString degw;
    QString degs;
    QString unitName;
    QString unitGradation;
    QString unitNature;
    QString unitProperty;
    QString unitCategory;
    QString unitLevel;
    QString affiliation;

    QSqlQuery qugra;//层次
    QSqlQuery qunatrue;//属性
    QSqlQuery quca;//性质
    QSqlQuery quoc;//类别
    QSqlQuery qulev;//级别
    QSqlQuery quaff;//隶属关系

    QTreeWidgetItemIterator it(ui->treeWidget_2);
    while (*it)
    {
        if((*it)->text(0)=="性别")
        {
            if((*it)->child(0)->text(0)=="男")
                sex = QString(" and Sex = '1'");
            if((*it)->child(0)->text(0)=="女")
                sex = QString(" and Sex = '0'");
        }
        if((*it)->text(0)=="民族")
        {
            QString nationCode;
            queryNation.exec(QString("select NationID from NationCode where Nation = '%1'").arg((*it)->child(0)->text(0)));
            while(queryNation.next())
            {
                nationCode = queryNation.value(0).toString();
                //qDebug()<<nationCode;
            }
            nation = QString(" and NationID = '%1'").arg(nationCode);

        }
        if((*it)->text(0)=="政治面貌")
        {
            QString politicCode;
            queryPolitic.exec(QString("select PoliticID from PoliticCode where Politic = '%1'").arg((*it)->child(0)->text(0)));
            while(queryPolitic.next())
            {
                politicCode = queryPolitic.value(0).toString();
                //qDebug()<<politicCode;
            }
            politic = QString(" and PoliticID = '%1'").arg(politicCode);

        }
        if((*it)->text(0)=="已认定三龄一历")
        {
            if((*it)->child(0)->text(0) == "是")
            {
                threeOne = QString(" and ThreeOne = '1'");
            }
            else
            {
                threeOne = QString(" and ThreeOne = '0'");
            }

        }
        if((*it)->text(0)=="干部身份")
        {
            idenCate = QString(" and IdenCate = '%1'").arg((*it)->child(0)->text(0));

        }
        if((*it)->text(0)=="干部状态")
        {
            QString manageStatusCode;
            queryManageStatus.exec(QString("select ManageStatusID from ManageStatusCode where ManageStatus = '%1'").arg((*it)->child(0)->text(0)));
            while(queryManageStatus.next())
            {
                manageStatusCode = queryManageStatus.value(0).toString();
                //qDebug()<<manageStatusCode;
            }
            manageStatus = QString(" and ManageStatusID = '%1'").arg(manageStatusCode);

        }
        if((*it)->text(0)=="职务级别")
        {
            QString rankCode;
            queryRank.exec(QString("select RankID from RankCode where RankName = '%1'").arg((*it)->child(0)->text(0)));
            while(queryRank.next())
            {
                rankCode = queryRank.value(0).toString();
                //qDebug()<<rankCode;
            }
            rank = QString(" and RankID = '%1'").arg(rankCode);

        }
        if((*it)->text(0)=="在职学历")
        {
            QString eduCode;
            queryEdu.exec(QString("select EducationID from EducationCode where Education = '%1'").arg((*it)->child(0)->text(0)));
            while(queryEdu.next())
            {
                eduCode = queryEdu.value(0).toString();
                //qDebug()<<eduCode;
            }
            eduw = QString(" and WorkORSchool = '0' and EduNum = '%1'").arg(eduCode);
            //qDebug()<<eduw;
        }
        if((*it)->text(0)=="在职学位")
        {
            QString degCode;
            queryDeg.exec(QString("select DegreeID from DegreeCode where Degree = '%1'").arg((*it)->child(0)->text(0)));
            while(queryDeg.next())
            {
                degCode = queryDeg.value(0).toString();
                //qDebug()<<degCode;
            }
            degw = QString(" and WorkORSchool = '0' and AcademicDe = '%1'").arg(degCode);
            //qDebug()<<degw;
        }
        if((*it)->text(0)=="全日制学历")
        {
            QString eduCode;
            queryEdu.exec(QString("select EducationID from EducationCode where Education = '%1'").arg((*it)->child(0)->text(0)));
            while(queryEdu.next())
            {
                eduCode = queryEdu.value(0).toString();
                //qDebug()<<eduCode;
            }
            edus = QString(" and WorkORSchool = '1' and EduNum = '%1'").arg(eduCode);
            //qDebug()<<edus;
        }
        if((*it)->text(0)=="全日制学位")
        {
            QString degCode;
            queryDeg.exec(QString("select DegreeID from DegreeCode where Degree = '%1'").arg((*it)->child(0)->text(0)));
            while(queryDeg.next())
            {
                degCode = queryDeg.value(0).toString();
                qDebug()<<degCode;
            }
            degs = QString(" and WorkORSchool = '1' and AcademicDe = '%1'").arg(degCode);
            qDebug()<<degs;
        }
        if((*it)->text(0)=="单位名称")
        {
            unitName = QString(" and unitname ='%1'").arg((*it)->child(0)->text(0));
            qDebug()<< (*it)->child(0)->text(0);
//            queryUnit.exec(QString("select unitid from unit where unitname = '%1'").arg((*it)->child(0)->text(0)));
//            while(queryUnit.next())
//            {

//                unitId = queryUnit.value(0).toInt();
//                qDebug()<<unitId;
//            }
        }
        if((*it)->text(0)=="单位层次")
        {
            QString ugCode;
            qugra.exec(QString("select UnitGradationId from UnitGradationCode where UnitGradationName = '%1'").arg((*it)->child(0)->text(0)));
            while(qugra.next())
            {
                ugCode = qugra.value(0).toString();
                //qDebug()<<ugCode;
            }
            unitGradation = QString(" and unitgradation ='%1'").arg(ugCode);
        }
        if((*it)->text(0)=="单位属性")
        {
            QString unCode;
            qunatrue.exec(QString("select UnitNatrueId from UnitNatrueCode where UnitNatrueName = '%1'").arg((*it)->child(0)->text(0)));
            while(qunatrue.next())
            {
                unCode = qunatrue.value(0).toString();
                //qDebug()<<unCode;
            }
            unitNature = QString(" and unitnatrue = '%1'").arg(unCode);
        }
        if((*it)->text(0)=="单位性质")
        {
            QString ucCode;
            quca.exec(QString("select UnitCategoryID from UnitCategoryCode where UnitCategory = '%1'").arg((*it)->child(0)->text(0)));
            while(quca.next())
            {
                ucCode = quca.value(0).toString();
                //qDebug()<<ucCode;
            }
            unitProperty = QString(" and unitproperty = '%1'").arg(ucCode);
        }
        if((*it)->text(0)=="单位类别")
        {
            QString uocCode;
            quoc.exec(QString("select UnitOfCategoryId from UnitOfCategoryCode where UnitOfCategoryName = '%1'").arg((*it)->child(0)->text(0)));
            while(quoc.next())
            {
                uocCode = quoc.value(0).toString();
                //qDebug()<<uocCode;
            }
            unitCategory = QString(" and unitcategory = '%1'").arg(uocCode);
        }
        if((*it)->text(0)=="单位级别")
        {
            QString ulCode;
            qulev.exec(QString("select UnitLevelID from UnitLevelCode where UnitLevel = '%1'").arg((*it)->child(0)->text(0)));
            while(qulev.next())
            {
                ulCode = qulev.value(0).toString();
                qDebug()<<ulCode;
            }
            unitLevel = QString(" and unitlevel = '%1'").arg(ulCode);
        }
        if((*it)->text(0)=="单位隶属关系")
        {
            QString uaCode;
            quaff.exec(QString("select AffiliationId from AffiliationCode where AffiliationName = '%1'").arg((*it)->child(0)->text(0)));
            while(quaff.next())
            {
                uaCode = quaff.value(0).toString();
                //qDebug()<<uaCode;
            }
            affiliation = QString(" and affiliation = '%1'").arg(uaCode);
        }

        ++it;
    }

    //1)筛选单位信息
    sqlUnit = QString("select unitid from unit where unitid != 0 ");
    sqlUnit = sqlUnit + unitName + unitGradation + unitNature + unitProperty + unitCategory + unitLevel + affiliation;
    //qDebug()<<sqlUnit;
    if(!unitName.isEmpty() or !unitGradation.isEmpty() or !unitNature.isEmpty() or !unitProperty.isEmpty() or !unitCategory.isEmpty() or !unitLevel.isEmpty() or !affiliation.isEmpty())
    {
        queryUnit.exec(sqlUnit);
        while(queryUnit.next())
        {
            unitId = queryUnit.value(0).toInt();
            //qDebug()<<unitId;
            //2）筛选满足单位条件的干部信息
            sqlAll = QString("select IDNum from CadreInfo where UnitID = '%1'").arg(unitId);
            sqlAll = sqlAll + sex + nation + threeOne + idenCate + manageStatus + rank;
            qDebug()<<sqlAll;
            queryAll.exec(sqlAll);
            while(queryAll.next())
            {
                //3）进一步筛选满足学位学历条件的干部
                if(!eduw.isEmpty() or !edus.isEmpty() or !degw.isEmpty() or !degs.isEmpty())
                {
                    sqlAddEdu = QString("select IDNum from Edu where IDNum = '%1'").arg(queryAll.value(0).toString());
                    sqlAddEdu = sqlAddEdu + eduw + edus + degw + degs;
                    //qDebug()<< sqlAddEdu;
                    query.exec(sqlAddEdu);
                    while (query.next())
                    {
                        idNum = query.value(0).toString();
//                        qDebug()<< idNum;
//                        chooseCadre.dealData(idNum);
                        wtm.append(idNum);
                    }
                }
                else
                {
                    idNum = queryAll.value(0).toString();
//                    qDebug()<< idNum;
//                    chooseCadre.dealData(idNum);
                    wtm.append(idNum);
                }

            }
        }
    }
    else
    {
        sqlAll = QString("select IDNum from CadreInfo where ");
        sqlAll = sqlAll + birthScale + sex + nation + threeOne + idenCate + manageStatus + rank;
        qDebug()<<sqlAll;
        queryAll.exec(sqlAll);
        while(queryAll.next())
        {
            //3）进一步筛选满足学位学历条件的干部
            if(!eduw.isEmpty() or !edus.isEmpty() or !degw.isEmpty() or !degs.isEmpty())
            {
                sqlAddEdu = QString("select IDNum from Edu where IDNum = '%1'").arg(queryAll.value(0).toString());
                sqlAddEdu = sqlAddEdu + eduw + edus + degw + degs;
                qDebug()<< sqlAddEdu;
                query.exec(sqlAddEdu);
                while (query.next())
                {
                    idNum = query.value(0).toString();
//                    qDebug()<< idNum;
//                    chooseCadre.dealData(idNum);
                    wtm.append(idNum);
                }
            }
            else
            {
                idNum = queryAll.value(0).toString();
//                qDebug()<< idNum;
//                chooseCadre.dealData(idNum);
                wtm.append(idNum);
            }
        }
    }


    //***********************************************************************************************
        for(int i = 0; i < ljt.count(); i++){
            qDebug()<<ljt[i];

            for(int j = 0; j < wtm.count(); j++){
                qDebug()<<wtm[j];

                if(ljt[i]==wtm[j]){
//                            emit sendData3(wtm[j]);//发送查询的干部IDNum
                    qDebug()<<idNum;
                    chooseCadre.dealData(wtm[j]);
                    chooseCadre.show();
                    this->close();

                }
            }
        }
        if(id=="NULL"){
            QMessageBox::information(this, tr("提示信息"), tr("系统中未找到查询干部的信息"));
        }
        else if(idNum=="NULL"){
            QMessageBox::information(this, tr("提示信息"), tr("系统中未找到查询干部的信息"));
        }
        flog=0;

}

//接受choose传来的num
void CadreSearch::recvSend(QString num)
{
    //qDebug() << num;
    emit sendRecvNum(num);
}

//双击添加
void CadreSearch::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column)
{
    if(item->parent())
    {
        QTreeWidgetItem *parent=new QTreeWidgetItem(ui->treeWidget_2);
        parent->setText(column,item->parent()->text(0));
        QTreeWidgetItem *child=new QTreeWidgetItem(parent);
        child->setText(column,item->text(0));
        ui->treeWidget_2->expandItem(parent);
    }

}

//双击删除
void CadreSearch::on_treeWidget_2_itemDoubleClicked(QTreeWidgetItem *item, int column)
{
    //int col = column;
    if(item->parent())
    {
        //item->parent()->removeChild(item);
        delete item->parent();
    }
}

//左侧条件筛选-参数查找
void CadreSearch::on_buttonFind_1_clicked()
{
    QString coFilter = ui->lineEdit_13->text();
    QTreeWidgetItemIterator it(ui->treeWidget);
        while (*it)
        {
            //QTreeWidgetItem是否满足条件---这里的条件可以自己修改
            if((*it)->text(0).contains(coFilter))
            {
                (*it)->setHidden(false);
                QTreeWidgetItem *item = *it;
                //显示父节点
                while (item->parent())
                {
                    //item->setHidden(false);
                    item->parent()->setHidden(false);

                    item = item->parent();

                    //ui->treeWidget_2->expandItem(item);
                }
            }
            else
            {
                 //不满足满足条件先隐藏，它的子项目满足条件时会再次让它显示
                (*it)->setHidden(true);
            }
            ++it;
        }
}

//右侧条件筛选-参数查找
void CadreSearch::on_buttonFind_2_clicked()
{
    QString coFilter = ui->lineEdit_14->text();
    QTreeWidgetItemIterator it(ui->treeWidget_2);
        while (*it)
        {
            //QTreeWidgetItem是否满足条件
            if((*it)->text(0).contains(coFilter))
            {
                (*it)->setHidden(false);
                QTreeWidgetItem *item = *it;
                //显示父节点
                while (item->parent())
                {
                    //item->setHidden(false);
                    item->parent()->setHidden(false);

                    item = item->parent();

                    //ui->treeWidget_2->expandItem(item);
                }
            }
            else
            {
                 //不满足满足条件先隐藏，它的子项目满足条件时会再次让它显示
                (*it)->setHidden(true);
            }
            ++it;
        }
}
